import os
from openai import OpenAI


# 配置信息
API_KEY = "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"  # 替换为你的API密钥


PROXY = "http://127.0.0.1:7890"  # 替换为你的代理地址

# 设置全局代理环境变量
os.environ["https_proxy"] = PROXY


def simple_gpt_test():
    try:
        # 初始化 OpenAI 客户端
        client = OpenAI(
            api_key=API_KEY
        )

        # 发送请求询问模型能做什么
        response = client.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[{"role": "user", "content": "你能做什么？"}]
        )

        # 打印模型回复
        print("模型回复：")
        print(response.choices[0].message.content)

    except Exception as e:
        print(f"连接失败，错误信息：{str(e)}")


if __name__ == "__main__":
    print("正在连接 GPT 模型...")
    simple_gpt_test()